<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<script>
    //--------------------------------------------------------------------------------------------------------------------------------
    var callInfoCustomerId = $('#customerId').val();
    var layerIndex,
        /* 事件 */
        Events = {
            //得到查询的参数
            tableParams: function (params) {
                params.orderId = $("#orderId").val();
                params.orderType = $("#orderType").val();
                params.fThirdStatusID = $("#fthirdStatusID").val();
                params.fNo = $("#fNo").val();
                return params;
            },
            getHeight: function () {
                return $(window).height() - ($(".search-panel").outerHeight() || 60) - 45;
            },
            // 查询数据
            searchAction: function () {
                //初始化table上面的工具组
                //初始化table上面的工具组
                Page.Table.bootstrapTable('refreshOptions', {pageNumber: 1, pageSize: 20});
            },
            statusAction: function (value, row, index) {
                if (value != null && value == "1") {
                    return "是";
                } else {
                    return "否";
                }
            },
            relationAction: function (row) {

                Common.confirm("您确定要重新同步吗？", "请谨慎操作！",
                    function (isConfirm) {
                        if (isConfirm) {
                            $.post("updateAction.json", {
                                "orderId": row.orderId,
                                "orderType":row.orderType
                            }, function (ret) {
                                if (ret.success) {
                                    Common.alert("更新成功！", function () {
                                        Events.searchAction();
                                    });
                                } else {
                                    var msg = ret.message || "更新失败";
                                    Common.error(msg);
                                }
                            })
                        } else {
                            Common.error("您取消了更新操作！");
                        }
                    });
            },
            fkOrderAction: function () {

                Common.confirm("您确定要同步收款单吗？","",
                    function (isConfirm) {
                        if (isConfirm) {
                            $.post("fkOrderSynchAction.json", {
                            }, function (ret) {
                                if (ret.success) {
                                    Common.alert("同步中请稍后！", function () {
                                        Events.searchAction();
                                    });
                                } else {
                                    var msg = ret.message || "同步失败！";
                                    Common.error(msg);
                                }
                            })
                        } else {
                            Common.error("您取消了更新操作！");
                        }
                    });
            },
            ckOrderAction: function () {

                Common.confirm("您确定要同步出库单吗？","",
                    function (isConfirm) {
                        if (isConfirm) {
                            $.post("ckOrderSynchAction.json", {
                            }, function (ret) {
                                if (ret.success) {
                                    Common.alert("同步中请稍后！", function () {
                                        Events.searchAction();
                                    });
                                } else {
                                    var msg = ret.message || "同步失败！";
                                    Common.error(msg);
                                }
                            })
                        } else {
                            Common.error("您取消了更新操作！");
                        }
                    });
            },
            rkOrderAction: function () {

                Common.confirm("您确定要同步入库单吗？","",
                    function (isConfirm) {
                        if (isConfirm) {
                            $.post("rkOrderSynchAction.json", {
                            }, function (ret) {
                                if (ret.success) {
                                    Common.alert("同步中请稍后！", function () {
                                        Events.searchAction();
                                    });
                                } else {
                                    var msg = ret.message || "同步失败！";
                                    Common.error(msg);
                                }
                            })
                        } else {
                            Common.error("您取消了更新操作！");
                        }
                    });
            },
        },
        ActionEvents = {
            'click .fn-relation': function (e, value, row, index) {
                Events.relationAction(row);
            },
            actionFormatter: function (value, row) {
                var content = [];
                if (row.fthirdStatusID == '1') {
                    content.push('<button type="button" title="解锁" class="btn btn-primary btn-xs list-btn fn-relation">解锁</button>');
                }
                return content.join('');
            },
        },
        /* 画面对象 */
        Page = {
            // 当前结点
            currNode: {},
            // 表格
            Table: $("#listTable"),

            // 初始化Validator
            initValidator: function () {

            },

            // 事件初期化
            initEvents: function () {
                // 查询按钮按下事件
                $(".fn-search").click(Events.searchAction);
                $(".fn-fkOrder").click(Events.fkOrderAction);
                $(".fn-ckOrder").click(Events.ckOrderAction);
                $(".fn-rkOrder").click(Events.rkOrderAction);
            },

            // 画面初始化
            initialize: function () {
                Page.Table.bootstrapTable({
                    height: Events.getHeight(),
                    method: 'get', //这里要设置为get，不知道为什么 设置post获取不了
                    url: webRoot + "/system/order/searchAction.json",
                    dataType: "json",
                    search: false,
                    iconSize: 'outline',
                    pagination: true,
                    pageSize: 20,
                    pageNumber: 1,
                    sidePagination: 'server',//设置为服务器端分页
                    queryParams: Events.tableParams, //参数   q
                    queryParamsType: 'limit',
                });

                setTimeout(function () {
                    Page.Table.bootstrapTable('resetView');
                }, 200);

                $(window).resize(function () {
                    Page.Table.bootstrapTable("resetView", {
                        height: Events.getHeight()
                    });
                });

            },

            init: function () {
                Page.initialize();
                Page.initEvents();
                Page.initValidator();
            }
        };

    jQuery(document).ready(function () {
        Page.init();
    });
</script>
